package com.example.wechat.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wechat.R;
import com.example.wechat.adapter.CardAdapter;
import com.example.wechat.model.Card;
import java.util.ArrayList;
import java.util.List;

public class CardActivity extends AppCompatActivity implements CardAdapter.OnCardClickListener {
    private RecyclerView cardList;
    private CardAdapter cardAdapter;
    private List<Card> cards;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card);

        // 设置工具栏
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowTitleEnabled(true);
        }

        // 初始化卡券列表
        cardList = findViewById(R.id.card_list);
        cardList.setLayoutManager(new LinearLayoutManager(this));
        
        // 添加示例卡券
        cards = new ArrayList<>();
        cards.add(new Card(R.drawable.ic_card, "会员卡", "有效期至：2024-12-31"));
        cards.add(new Card(R.drawable.ic_coupon, "优惠券", "满100减20"));
        cards.add(new Card(R.drawable.ic_ticket, "电影票", "有效期至：2024-06-30"));

        cardAdapter = new CardAdapter(this, cards, this);
        cardList.setAdapter(cardAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCardClick(int position) {
        Card card = cards.get(position);
        Toast.makeText(this, "查看" + card.getTitle(), Toast.LENGTH_SHORT).show();
        // TODO: 实现卡券详情功能
    }
} 